using B.S.NewMedical.Api.Write.Application.Command.Payment;
using B.S.NewMedical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.NewMedical.Api.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PaymentController : ControllerBase
    {
        private readonly IMediator _mediator;

        public PaymentController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 药品支付
        /// </summary>
        /// <param name="command">药品支付命令</param>
        /// <returns>收费记录ID</returns>
        [HttpPost]
        public async Task<ApiResult<int>> PayForDrugs([FromBody] PayForDrugsCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);
                return new ApiResult<int> { Code = ApiEnum.Success, Msg = "支付成功", Data = result };
            }
            catch (Exception ex)
            {
                return new ApiResult<int> { Code = ApiEnum.Fail, Msg = ex.Message };
            }
        }

        /// <summary>
        /// 检查支付
        /// </summary>
        /// <param name="command">检查支付命令</param>
        /// <returns>收费记录ID</returns>
        [HttpPost]
        public async Task<ApiResult<int>> PayForCheckup([FromBody] PayForCheckupCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);
                return new ApiResult<int> { Code = ApiEnum.Success, Msg = "支付成功", Data = result };
            }
            catch (Exception ex)
            {
                return new ApiResult<int> { Code = ApiEnum.Fail, Msg = ex.Message };
            }
        }

        /// <summary>
        /// 检验支付
        /// </summary>
        /// <param name="command">检验支付命令</param>
        /// <returns>收费记录ID</returns>
        [HttpPost]
        public async Task<ApiResult<int>> PayForTest([FromBody] PayForTestCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);
                return new ApiResult<int> { Code = ApiEnum.Success, Msg = "支付成功", Data = result };
            }
            catch (Exception ex)
            {
                return new ApiResult<int> { Code = ApiEnum.Fail, Msg = ex.Message };
            }
        }
    }
} 